import http from '/@/serve/index';
import { formatQuery } from '/@/libs/utils/format';

const prefix: string = '/flu/tasks';

export const getTasks = (status: string | undefined, page: number, pageSize: number) =>
  http.get(
    `${prefix}?${formatQuery({
      query: status !== '' ? `status:${status}` : '',
      page,
      pageSize,
    })}`,
  );

export const getTaskDetail = (taskId: string) => http.get(`${prefix}/${taskId}`);

export const deleteTask = (taskId: string) => http.delete(`${prefix}/${taskId}`);

export const createTask = (task: any) => http.post(prefix, task);

export const cancelTask = (taskId: string) => http.post(`${prefix}/${taskId}/cancel`);

// 获取任务参数
export const getTypes = () => http.get(`${prefix}/params/types`);
export const getStatuses = () => http.get(`${prefix}/params/statuses`);
export const getKits = () => http.get(`${prefix}/params/kits`);
